package com.pig4cloud.pigx.user.feign;

import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.user.constant.WalletConstant;
import com.pig4cloud.pigx.user.dto.UpdateFuelBalanceDTO;
import com.pig4cloud.pigx.user.service.FuelAccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 燃料账户feign
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/feign/fuel_account")
public class FuelAccountFeignImpl {

    private final FuelAccountService fuelAccountService;


    /**
     * 修改燃料账户余额
     *
     * @param dto  dto
     * @param from from
     * @return r
     */
    @Inner
    @PutMapping("/balance")
    public BigDecimal updateBalance(@RequestBody UpdateFuelBalanceDTO dto, String from) {
        return fuelAccountService.updateBalance(dto);
    }

    /**
     * 查询用户燃料账户额度
     *
     * @param userId 用户id
     * @param from   标记内部请求
     * @return {@link R< BigDecimal>}
     * @since 2022/12/10 15:38
     */
    @Inner
    @GetMapping("/balance")
    R<BigDecimal> getBalance(@RequestParam("userId") Long userId, @RequestHeader(SecurityConstants.FROM) String from) {
        return R.ok(fuelAccountService.getBalance(userId, WalletConstant.USDT));
    }

}
